/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package bugsandcritters;

import java.awt.*;
import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;
import java.io.File;
/**
 *
 * @author Student
 */
public class BasicSlider extends HudBasic
{
    public int Value; 
    public int MinValue;
    public int MaxValue;
    public String Text;
    public int SliderPos;
    
    
    @Override
    public void OnClick()
    {
        Value = (int) (MinValue + (HudManager.MouseX - X) / Width * 
                (MaxValue - MinValue));
        
        Value = Math.max(MinValue, Math.min(MaxValue, Value));
        SliderPos = (int)HudManager.MouseX;
        SliderPos = Math.max(X, Math.min(SliderPos, X+Width));
    }
    
    @Override
    public void Draw(Graphics g)
    {
        if(Width == 0)
        {
            Width = 228;
            Height = 64;
        }
        if(SliderPos == 0)
            SliderPos = (int)(X + (Value - MinValue)/ 
                    (MinValue-MaxValue) * Width);
        
        g.setColor(Color.WHITE);
        g.drawString(Text + Value, X + (int)(Width*0.25), Y);
        g.drawRect(X, (int)(Y + Height * (1.0/3.0)), Width, 
                (int)( Height * (1.0/3.0)));
        g.drawRect(SliderPos-2, Y, 4, Height);
    }
    
}
